<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="base" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>设备管理</title>
  <link href="${base}/assets/css/public.css" rel="stylesheet">
  <link href="${base}/assets/css/list.css" rel="stylesheet">
  <script src="${base}/assets/js/jquery.min.js"></script>
  <link rel="stylesheet" type="text/css" href="${base}/assets/css/jquery.searchableSelect.css" />
  <script type="text/javascript" src="${base}/assets/js/jquery.searchableSelect.js"></script> 
  <style>
	#pageshow{
		height:40px;
		padding-left: 30%;
	}
	#pageshow a{
		float:left;
		    text-decoration: none;
		font-family: consolas;
	}
	#pagenum{
		float:left;
	}
</style> 
</head>
<body>
<input type="hidden" id="pageNo" value="${pageNo}"/>
<div class="top">
<c:import url="../commons/top.jsp"/>
</div>
<div class="wrap">

  <div class="side">
  <c:import url="../commons/sidebar.jsp"/>
  </div>
  <div class="cont">
    <div class="bread">
      <span>设备管理</span><span>&nbsp;&gt;&nbsp;</span><span>批量修改</span>
      <c:if test="${admin.utype=='1'}">   
      <div class="excel-add">
      </div>
      </c:if>  
      <div class="clear"></div>
    </div>
    <div class="cate">
          <ul>
              <li>
                  <span>所在位置：</span>
                  <select id="wid" name="wid">
		             <option value="">--请选择--</option>
		               <c:forEach items="${whlist}" var="w">
		                    <option value="${w.id}">${w.whname}</option>
		           		</c:forEach>
		          </select>
              </li>
              <li>
                  <span>所属分类：</span>
                  <select  id="cid" name="cid">
                     <option value="">--请选择--</option>
                      <c:forEach items="${maxc}" var="m">
                          <option value="${m.id}">${m.name}</option>
                      </c:forEach>
                   </select>
				</li>
              <li>
                  <span>功能分类：</span>
				  <div id="fciddiv">
                  <select  id="fcid" name="fcid" >
                     <option value="">--请选择--</option>
                   </select>
				  </div>
              </li>
			  <li>
                  <span>设备分类:</span>
				  <div class="group-add" style="position:relative;z-index:8" id="dciddiv">
                  <select id="dcid" name="dcid" >
					<option value="">--请选择--</option>
					</select>
				 </div>
              </li>
              <li><button onclick="findbtn()">查 找</button></li>
          </ul>
      </div>
    <table id="sample_editable_1" width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#e9e9f0" class="list">
      <thead>
        <tr style="background-color:#ccc;">
            <th>所属类别</th>
            <th>功能类别</th>
            <th>设备类别</th>
            <th>品       牌 </th> 
            <th>旧  编 号 </th>
            <th>编       号</th>
            <th>型       号</th>
            <th>出厂编号</th>
            <th>投产年月</th>
            <th>折旧年限</th>
            <th>采购价格（元）</th> 
            <th>初始位置</th>
            <th>当前位置</th>
            <th>状       态</th>
            <th>备       注</th>
         </tr>
      </thead>
      <tbody>
      </tbody>
    </table>
	<div style=" withd:100%;text-align:center;">
	      <button onclick="batchbofei()" type="button" style="margin-left: 0 !important;">批量报废</button>
	      <button onclick="batchdelect()" type="button" style="margin-left: 0 !important;">批量删除</button>
	      
	</div>
  <div class="clear"></div>
</div>
<script type="text/javascript">
$(function(){
	$('#cid').searchableSelect({  
        afterSelectItem: function(){  
           var fsv= this.holder.data("value");
           if(fsv!=null && fsv!=''){
            	$.ajax({
					url: '${base}/back/searchmidc.do?pid='+fsv,
					async:false,
					dataType:"json",
					type:"post",
					success:function (data){
						$('#fciddiv').html("");
						var list = data.midc;
						if(list.length>0){
							var sel = '<select id="fcid" name="fcid" ><option value=""></option>'
							$.each(list,function(index,item){
								 sel +='<option value=" '+
										item.id + '">'+item.name+
									'</option>';
							});
							sel += '</select>';
							$('#fciddiv').append(sel);
							fcidcaozuo();
						}else{
							var sel = '<select id="fcid" name="fcid" ><option value="">无子分类</option></select>';
							$('#fciddiv').append(sel);
							$('#fcid').searchableSelect();
						} 	
					},
				});
            }
        }	 
    });
	function fcidcaozuo(){
		$('#fcid').searchableSelect({  
	        afterSelectItem: function(){  
	            var fsv= this.holder.data("value");
	            if(fsv!=null && fsv!=''){
	             	$.ajax({
	 					url: '${base}/back/searchmidc.do?pid='+fsv,
	 					async:false,
	 					dataType:"json",
	 					type:"post",
	 					success:function (data){
	 						$('#dciddiv').html("");
	 						var list = data.midc;
	 						if(list.length>0){
								var sel = '<select id="dcid" name="dcid" ><option value=""></option>'
								$.each(list,function(index,item){
									 sel +='<option value=" '+
											item.id + '">'+item.name+
										'</option>';
								});
								sel += '</select>';
								$('#dciddiv').append(sel);
								$('#dcid').searchableSelect();
							}else{
								var sel = '<select id="fcid" name="fcid" ><option value="">无子分类</option></select>';
								$('#dciddiv').append(sel);
								$('#dcid').searchableSelect();
							} 
						}, 
	 				});
	             }	
	         }  
	     });
	}
	$('#wid').searchableSelect();
});
	function findbtn(){
		var wid = $('#wid option:selected') .val();
		var cid = $('#cid option:selected') .val();
		var fcid= $('#fcid option:selected') .val();
		var dcid= $('#dcid option:selected') .val();
		$.ajax({
			  type: "POST",
			  dataType: "json", // 数据格式:JSON
			  url: '${base}/back/findvbatch.do',
			  data: {wid:wid,cid:cid,fcid:fcid,dcid:dcid},
			  success: function (data) {
				if(data.ddlist != null){
					$("#sample_editable_1 tbody").html("");
					$.each(data.ddlist,function(i,result){
						var tstr = "";
						if(result["status"]=='1'){
							tstr="正常";
						}else if(result["status"]=='2'){
							tstr="已出库";
						}else if(result["status"]=='3'){
							tstr="已报废";
						}
						var item='<tr style="background-color:rgba(226, 223, 223);">'+
							'<td>'+result["ccname"]+'</td>'+
							'<td>'+result["cfname"]+'</td>'+
							'<td>'+result["cdname"]+'</td>'+
							'<td>'+result["brand"]+'</td>'+
							'<td>'+result["oldno"]+'</td>'+
							'<td>'+result["no"]+'</td>'+
							'<td>'+result["xhno"]+'</td>'+
							'<td>'+result["ccno"]+'</td>'+
							'<td>'+result["tcrq"].substring(0,10)+'</td>'+
							'<td>'+result["zjnx"]+'</td>'+
							'<td>'+result["cgjg"]+'</td>'+
							'<td>'+result["oriwhname"]+'</td>'+
							'<td>'+result["whname"]+'</td>'+
							'<td>'+tstr+'</td>'+
							'<td><a href="#" style="background: #4876FF" title=" '+result["remark"]+' ">'+result["remark"].substring(0,10)+'...</a></td>'+
						'</tr>';
						$("#sample_editable_1 tbody").append(item);
					})
				}
			  }
		});
	}
	function batchbofei(){
		if(($("#sample_editable_1 tr").length - 1)<=0){
			alert("无数据不能操作！！");
			return;
		}
		$.ajax({
			  type: "POST",
			  dataType: "json", // 数据格式:JSON
			  url: '${base}/back/batchbofei.do',
			  success: function (data) {
				if(data.ok == 'ok'){
					alert("操作成功！！");
					findbtn();
				}
			  }
		});
	}
	function batchdelect(){
		if(($("#sample_editable_1 tr").length - 1)<=0){
			alert("无数据不能操作！！");
			return;
		}
		var mymessage=window.confirm('批量删除设备后设备将不存在！！请谨慎操作！！');  
	    if(mymessage==true){  
	    	$.ajax({
				  type: "POST",
				  dataType: "json", // 数据格式:JSON
				  url: '${base}/back/batchdelect.do',
				  success: function (data) {
					if(data.ok == 'ok'){
						alert("操作成功！！");
						findbtn();
					}
				  }
			});
	    }else if(mymessage==false){  
	    	 return; 
	    }
		
	}
</script>
</body>
</html>